package reviewAlgorithms.dynamicProgramming;

public class LengthOfLIS {
    public static void main(String[] args) {
        int[] nums = {1,3,6,7,9,4,10,5,6};
        System.out.println(lengthOfLIS(nums));
    }
    public static int lengthOfLIS(int[] nums) {
        if (nums == null || nums.length < 1){
            return 0;
        }
        int[] dp = new int[nums.length];
        dp[0] = 1;
        for (int i = 1; i < nums.length; i++) {
            int index = -1;
            for (int j = i - 1; j > -1; j--) {
                if (index == -1){
                    if (nums[i] > nums[j]){
                        index = j;
                    }
                }else {
                    if (nums[i] > nums[j] && dp[index] < dp[j]){
                        index = j;
                    }
                }
            }
            if (index == -1){
                dp[i] = 1;
            }else {
                dp[i] = dp[index] + 1;
            }
        }
        int max = 0;
        for (int i = 0; i < dp.length; i++) {
            max = Math.max(max,dp[i]);
        }
        return max;
    }
}
